package com.bing.controller;

import com.bing.controller.blog.HelloBlog;
import com.bing.entity.Post;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by kaibb on 16-1-17.
 */
@Controller
public class IndexController {

    private static final Logger LOGGER = LoggerFactory.getLogger(IndexController.class);
    private static final String PAGE = "page/";
    @Autowired
    private HelloBlog helloBlog;

    @RequestMapping("/")
    public String index(Model model) {
        return helloBlog.index(1, model);
    }

    @RequestMapping("robots.txt")
    @ResponseBody
    public String robots() {
        return "User-agent: * \n" +
                "Allow: /\n";
    }

    @RequestMapping("/page/about")
    public String about(Model model) {
        LOGGER.info("跳转页面到 --> {}", "about" );
        Post post =new Post();
        post.setTitle("刘凯兵的简历");
        post.setKeyword("刘凯兵的简历");
        model.addAttribute(post);
        return PAGE +"about";
    }

    @RequestMapping("/page/{page}")
    public String gotoPage(@PathVariable String page) {
        LOGGER.info("跳转页面到 --> {}", page );
        return PAGE +page;
    }
}
